﻿@model MileageStats.Web.Models.DashboardViewModel       

@if (!Html.IsRenderingForMustache())
{
    Layout = "~/Views/Shared/_Layout.Mobile.cshtml";
    ViewBag.Title = "Dashboard";
}

<nav>
    <ol class="tabs">
        <li><a href="@Url.Action("Index", "Dashboard")" class="selected">Dashboard</a></li>
        <li><a href="@Url.Action("Index", "Chart")">Charts</a></li>
    </ol>
</nav>

@{ Html.RenderPartial("_Flash.Mobile"); }

@using (var section  = Mustache.Section("Model")){
    <div class="view" id="view">
    <h2>
        Statistics</h2>
    <div class="stats">
        <dl>
            <dt class="mpg-label">MPG</dt>
            <dd class="mpg">
                @Mustache.Value(m => m.FleetSummaryStatistics.AverageFuelEfficiency)
            </dd>
            <dt class="mile-label">/mile</dt>
            <dd class="mile">
                @Mustache.Value(m => m.FleetSummaryStatistics.AverageCostToDrive)
            </dd>
            <dt class="month-label">/month</dt>
            <dd class="month">
                @Mustache.Value(m => m.FleetSummaryStatistics.AverageCostPerMonth)
            </dd>
        </dl>
    </div>
    <h2>
        Vehicles</h2>
    @foreach (var vehicle in Mustache.Loop(m => m.VehicleListViewModel.Vehicles))
    {
        var overdueReminderFlag = (!Html.IsRenderingForMustache() && vehicle.HasImminentReminders)? "class=\"flag\"" : string.Empty;
        
        <dl class="vehicle widget">
            <dt>
                <h2>
                    <a href="@Url.UnencodedAction("Details", "Vehicle", new { vehicleId = Mustache.Value(vehicle, i => i.VehicleId) })">@Mustache.Value(vehicle, i => i.Name)</a></h2>
            </dt>
            <dd>
                <table>
                    <tr>
                        <td>Average Fuel Efficiency</td>
                        <td>@Mustache.Value(vehicle, i => i.Statistics.AverageFuelEfficiency)/mpg
                        </td>
                    </tr>
                    <tr>
                        <td>Total Distance Travelled</td>
                        <td>@Mustache.Value(vehicle, i => i.Statistics.TotalDistance) mi
                        </td>
                    </tr>
                    <tr>
                        <td>Total Cost</td>
                        <td>
                            @Mustache.Value(vehicle, i => i.Statistics.TotalCost)
                        </td>
                    </tr>
                </table>
                <ol class="hbox button-group">
                    <li><a href="@Url.UnencodedAction("Details", "Vehicle", new { vehicleId = Mustache.Value(vehicle, i => i.VehicleId) })">
                        <span>Details</span></a></li>
                    <li><a href="@Url.UnencodedAction("List", "Fillup", new { vehicleId = Mustache.Value(vehicle, i => i.VehicleId) })">
                        <span>Fill Ups </span></a></li>
                    <li>
						<a id="reminderMenu_@(Mustache.Value(vehicle, i => i.VehicleId))" @overdueReminderFlag href="@Url.UnencodedAction("List", "Reminder", new { vehicleId = Mustache.Value(vehicle, i => i.VehicleId) })">
                        <span >Reminders</span></a></li>
                </ol>
            </dd>
        </dl>
    }
    <ol class="button-group">
        <li class="add icon"><a href="@Url.Action("Add", "Vehicle")"><span>Add New Vehicle</span></a></li>
    </ol>
    <h2>
        Imminent Reminders</h2>
    <ul class="fillup widget">
        <li>
            <table>
                <thead>
                    <tr>
                        <th>Reminder</th>
                        <th> Due on or at</th>
                    </tr>
                </thead>
                @foreach (var reminder in Mustache.Loop(m => m.ImminentReminders))
                {
                    var reminderId = Mustache.Value(reminder, i => i.Reminder.ReminderId);
                    var vehicleId = Mustache.Value(reminder, i => i.VehicleId);
                    var url = Url.UnencodedAction("Details", "Reminder", new { id = reminderId, vehicleId });
                    <tr>
                        <td>
                            <a href="@url">@Mustache.Value(reminder, i => i.Reminder.Title)</a>
                        </td>
                        <td>
                            <a href="@url">@Mustache.Value(reminder, i => i.Reminder.DueOnFormatted)</a>
                        </td>
                    </tr>
                }
            </table>
        </li>
    </ul>
</div>
}